package com.pay.ioopos;

import com.aggregate.pay.sanstar.SanstarApiFactory;
import com.aggregate.pay.sanstar.support.Merch;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ApiFactory {

    public static Merch initApi() {
        DataStore store = DataFactory.getDataStore();
        SanstarApiFactory.config(() -> store.getServerUrl(), new HttpClient());
        return new Merch(){

            @Override
            public String merchNo() {
                return store.getMerchNo();
            }

            @Override
            public String key() {
                return store.getTransKey();
            }

            @Override
            public String terminalNo() {
                return store.getTerminalNo();
            }

            @Override
            public String devSn() {
                return Utils.sn();
            }
        };
    }

    public static String generateOrderNo() {
        return DataFactory.getDataStore().getTransPrefix() + new SimpleDateFormat("yyMMddHHmmss").format(new Date()) + Utils.sn().substring(Utils.sn().length() - 3) + Math.round(Math.random() * 89 + 10);
    }
}
